<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template.xhtml">
	<ui:define name="corpo">

		<h:form id="formComp">

			<p:growl id="growl" life="2500"></p:growl>
			
				<h:outputLabel value="Disciplina:"></h:outputLabel>
				<p:autoComplete value="#{competenciaBean.idDisciplina}"
					completeMethod="#{competenciaBean.completaNomeDisciplina}"
					var="disc" itemLabel="#{disc.nome}" itemValue="#{disc.id}"
					dropdown="true" id="completeDisc" size="45"/>
				<p:watermark for="completeDisc"
					value="Digite o nome da disciplina para pesquisar"
					rendered="#{not empty disciplinaBean.disciplinas}"></p:watermark>

				<p:watermark for="completeDisc"
					value="Nenhuma disciplina cadastrada, favor incluir"
					rendered="#{empty disciplinaBean.disciplinas}"></p:watermark>
					
				<p:commandLink action="#{competenciaBean.grava}"
					update="tablecomp growl" title="Adicionar">
					<p:graphicImage value="resources/imagens/add.png" width="24px"
						height="24px" />
				</p:commandLink>

			<br /><br></br>

			<p:dataTable id="tablecomp" value="#{competenciaBean.competencias}"
				var="c"
				rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'par' : 'impar'}"
				rowIndexVar="rowIx" emptyMessage="nenhuma competência cadastrada">

				<f:facet name="header"> Competências</f:facet>

				<p:column headerText="Disciplina">
                                        #{c.disciplina.nome} 
                                        </p:column>

				<p:column headerText="Ação">
					<div align="center">
						<p:commandLink title="remover"
							oncomplete="removeCompetencia.show()"
							action="#{aulaBean.preencheAulasRelacionadasComCompetencia}"
							update=":formApaga:button :formApaga:tableAulaSelec">
							<f:setPropertyActionListener value="#{c}"
								target="#{aulaBean.competencia}" />
							<f:setPropertyActionListener
								target="#{competenciaBean.competencia}" value="#{c}" />
							<p:graphicImage value="resources/imagens/delete.png" width="24px"
								height="24px" />
						</p:commandLink>
					</div>
				</p:column>
			</p:dataTable>
		</h:form>

		<h:form id="formApaga">
			<p:dialog widgetVar="removeCompetencia" resizable="false"
				id="apagCompDialog" showEffect="fade" hideEffect="explode"
				closable="true" modal="true">


				<p:dataTable id="tableAulaSelec"
					value="#{aulaBean.aulasRelacionadas}" var="aula"
					rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'par' : 'impar'}"
					rowIndexVar="rowIx" emptyMessage="nenhuma aula relacionada">
					<f:facet name="header">
					As seguintes aulas estão relacionados com essa disciplina. 
					
						</f:facet>
					<p:column headerText="Professor">
                    	#{aula.competencia.professor.usuario.nome} 
                 	</p:column>
					<p:column headerText="Matricula">
                    	#{aula.competencia.professor.usuario.matricula} 
                 	</p:column>
					<p:column headerText="Dia">
                    	#{aula.disponibilidade.dia} 
                 	</p:column>
					<p:column headerText="Turno">
                    	#{aula.disponibilidade.turno} 
                 	</p:column>
					<p:column headerText="Horario">
                    	#{aula.disponibilidade.horario} 
                 	</p:column>

					<f:facet name="footer">
						<h:outputText rendered="#{not empty aulaBean.aulasRelacionadas}"
							value="Somente a Secretaria pode apagar esta competência">
						</h:outputText>

					</f:facet>
				</p:dataTable>

				<p:panel id="button" columns="2" cellpadding="4"
					style="margin:5px;">

					<p:commandButton value="Sim, remover"
						action="#{competenciaBean.remove}" update=":formComp:tablecomp"
						onclick="removeCompetencia.hide()"
						rendered="#{empty aulaBean.aulasRelacionadas}" />

					<p:commandButton value="Não remover"
						onclick="removeCompetencia.hide()"
						rendered="#{empty aulaBean.aulasRelacionadas}" />

					<p:commandButton value="Ok" onclick="removeCompetencia.hide()"
						rendered="#{not empty aulaBean.aulasRelacionadas}" />
				</p:panel>
			</p:dialog>
		</h:form>

	</ui:define>
</ui:composition>

</html>